﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Touch2Like.DAL;
using Touch2Like.Model;

namespace Touch2Like.Web.Admin.Popup
{
    public partial class AddKnowledge : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["ListID"]))
                {
                    Touch2Like.DAL.KnowledgeDAL knowledge = new Touch2Like.DAL.KnowledgeDAL();
                    KnowledgeInfo info = knowledge.GetByID(Convert.ToInt32(Request["ListID"]));

                    if (info != null)
                    {
                        tb_Title.Text = info.Title;
                        tb_Content.Text = info.Content;
                    }
                }
            }
        }

        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            Touch2Like.DAL.KnowledgeDAL knowledge = new Touch2Like.DAL.KnowledgeDAL();
            KnowledgeInfo info = new KnowledgeInfo();

            info.Title = tb_Title.Text;
            info.Content = tb_Content.Text;

            if (!string.IsNullOrEmpty(Request["ListID"]))
            {
                info.ListID = Convert.ToInt32(Request["ListID"]);
                knowledge.Update(info);
            }
            else
            {
                knowledge.Add(info);
            }

            ClientScript.RegisterStartupScript(this.GetType(), "update", "<script>parent.document.location.href=parent.document.location.href;parent.document.location.reload();</script>");
        }
    }
}